﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PerfumeShopManagement.Model;
using PerfumeShopManagement.DAL;
using PerfumeShopManagement.BLL;

namespace PerfumeShopManagement.View
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            login();
        }

        private void login()
        {
            string usernameEnter = txbUsername.Text;
            string passwordEnter = txbPassword.Text;
            if (new BllAccount().Login(usernameEnter, passwordEnter))
            {
                showMainScreen();
            }
        }

        private void showMainScreen()
        {
            frmMain mainView = new frmMain();
            mainView.Visible = true;
            mainView.FormClosed += new FormClosedEventHandler(mainView_FormClosed);
            this.Hide();
        }

        void mainView_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Enter))
            {
                login();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}
